﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.BLL.AppEngine.IService;
using Empires.RAL.Pump;
using Empires.RAL.Access;
using Empires.RAL.ORM;

namespace Empires.BLL.AppEngine.Implement
{
    public class TempleteService : ITempleteService
    {
        public TempleteInfo GetTempleteInfo(int id)
        {
            IAppTempleteAccess access = new AppTempleteDataPump();
            var temp = access.GetTempleteInfo<tb_style>(id);
            return new TempleteInfo()
            {
                TempleteName = temp.c_nvc_name,
                Descript = temp.c_nvc_descript,
                TempleteImages = Empires.CRL.Tools.StringPlus.SplitString(temp.c_nvc_templeteimage, ';', true).ToArray(),
                MainImage = temp.c_nvc_mainimage
            };
        }


        public int ApplyTempleteToCompany(int id, string master)
        {
            IAppUserAccess access = new AppUserDataPump();
            var user = access.GetUserEntity<tb_user>(master);
            if (user != null)
            {
                if (user.c_b_opened)
                {
                    Empires.RAL.Access.ICompanyBaseAccess cop = new Empires.RAL.Pump.CompanyBaseDataPump();
                    return cop.UpdateCompanyTempleteStyle(master, id);
                }
            }
            return 0;
        }
    }
   
}
